package metadata.schema;

import java.util.Hashtable;

public class Database {

	private int databaseNumber;
	private String databaseName;
	
	private Hashtable<String, Schema> tableTable;
	
	public Database(int databaseNumber, String databaseName) {
		this.databaseNumber = databaseNumber;
		this.databaseName = databaseName;
	}
	
	public int getNumber() { return databaseNumber; }
	
	public String getName() { return databaseName; }
	
	public boolean hasTable(String tableName) {
		return (tableTable.get(tableName) == null);
	}
	
	public Schema getTable(String tableName) {
		return tableTable.get(tableName);
	}
	
	public void createTable(String tableName) {
		// TODO: transaction?
		// check existence
		if (!tableTable.containsKey(tableName)) {
			Schema table = new Schema(tableName);
			tableTable.put(tableName, table);
			// TODO: write to disk
			// TODO: create file
		}
	}
	
	public void dropTable(String tableName) {
		// TODO: transaction?
		// check existence
		if (tableTable.containsKey(tableName)) {
			Schema table = tableTable.remove(tableName);
			// TODO: write to disk
			// TODO: remove file
		}
	}

}
